﻿using System.Security.Claims;
using Zhao.Models.DTO;
using Zhao.Models.Entity;

namespace Zhao.AuthServer.JwtService
{
    /// <summary>
    /// 颁发Ttoken的抽象类
    /// </summary>
    public abstract class CustomJWTService
    {
        /// <summary>
        /// 抽象函数，生成Token的，具体实现，留给实现类来实现---多种方式来实现
        /// </summary>
        /// <param name="admin">SysUserInfo，从数据库中查询出来以后</param>
        /// <param name="refreshToken"></param>
        /// <returns></returns>
        public abstract string CreateToken(AdminInfoDto logInDto, out string refreshToken);

        /// <summary>
        /// 生成token 准备用户的信息，写入到Claim
        /// </summary>
        /// <param name="logInDto"></param>
        /// <returns></returns>
        protected virtual List<Claim> UserToClaim(AdminInfoDto logInDto)
        {
            //准备有效载荷
            List<Claim> claimsArray = new List<Claim>()
            {
               new Claim(ClaimTypes.Sid, logInDto.Id.ToString()),
               new Claim(ClaimTypes.Name, logInDto.Name?? string.Empty),
               new Claim(ClaimTypes.OtherPhone,logInDto.Phone?? string.Empty),
               new Claim(ClaimTypes.Email, logInDto.Email?? string.Empty),
               new Claim(ClaimTypes.Role, logInDto.Role.ToString()),
               new Claim("VenueId",logInDto.VenueId.ToString())
            };

            return claimsArray;
        }
    }
}
